/* BMP085 Example

This is an example of using the BMP085 objext library

Typing any character returns the pressure data
Typing "a" sets the current ground level altitude
Typing "c" prints out the downloaded BMP085 calibration constants
Typing "+" offsets the altitude to 100 ft higher
Typing "-" offsets the altitude to 100 ft lower

*/

#include <Wire.h>;


#include <BMP085.h>
BMP085 pAlt;


void setup() {
  // Join I2C Bus
  Wire.begin();
  // Initialize serial communication 
  Serial.begin(9600);
  // Initialize pressure sensor
  pAlt.begin();
  
  
}

void loop() {
  
  
  if (Serial.available()) {
    char inByte = Serial.read();
    // Read/Calibrate the Temperature
    // Note that this would only need to be done every few seconds
    pAlt.get_temp();
    
    // Start the pressure measurement
    pAlt.start_pressure();
    
    // We'll wait here - normally would go off and do something else
    // and pick up the pressure next time through loop
    delay(30);
    
    // Read the pressure
    long p = pAlt.pressure();
    
    if (inByte == 'a') {
      // 'a' Entered - Set the Ground level to the current altitude
      pAlt.agl_0 = pAlt.altitude();
    } else if (inByte == 'c') {
      // 'c' Entered - Print out the internal BMP085 constants
      Serial.println("AC1, AC2, AC3, AC4, AC5, AC6:");
      Serial.println(pAlt.ACconst());  // Returns the internal "A" Constants, as a String (for debug)
      Serial.println("xB1, B2, MB, MC, MD, B5");
      Serial.println(pAlt.BMconst());
    } else if (inByte == '+') {
      // '+' Entered - Increment the altitude offset by 100'
      pAlt.alt_0 += 3048;    // 100 ft in cm
    } else if (inByte == '-') {
      // '-' Entered - Decrement the altitude offset by 100'
      pAlt.alt_0 -= 3048;
    }
    
    // Print out the Pressure and Altitude Data
    Serial.print("Pressure = ");
    Serial.print(p);
    Serial.println(" Pa");
    Serial.print("Altitude = ");
    Serial.print((pAlt.altitude()*10)/305);
    Serial.println(" ft");
    Serial.print("AGL = ");
    Serial.print(pAlt.agl());
    Serial.println(" cm");

  }
}
